<?php
namespace Database;

class Product extends Base
{

    public function __construct()
    {
        $this->setModel(MODEL_PRODUCT);
    }

    public function getList($categoryId, $recommendIn, $page, $limit)
    {
        $now = getDateTime();
        $sql = $this->getSql();
        $sql->field('*');
        $sql->table($this->getTable());
        $sql->where('id', '>', 0);
        if($categoryId){
            $sql->andWhere('dry_category', '=', $categoryId);
        }
        if($recommendIn){
            $sql->andWhere('dry_recommend', 'in', $recommendIn);
        }
        $sql->andWhere('dry_start_time', '<', $now['date_time']);
        $sql->andWhere('dry_end_time', '>', $now['date_time']);
        $sql->andWhere('dry_status', '=', 1);
        $sql->andWhere('dry_is_resource', '=', 0);
        $sql->setOrder('dry_sort', 'asc');
        $sql->setPage($page);
        $sql->setPageSize($limit);
        $sql->setLimit();
        $list = $this->fetchAll($sql->get());
        $count = $this->fetchColumn($sql->getTotalSql());
        return [
            'list' => $list,
            'count' => $count
        ];
    }

}